

<?php
if(isset($_POST["SO_query"])){
	
		if($_POST["SO_query"]=="recommendation_insert"){
			$p_type=$_POST['SO_type'];
			$p_subject=htmlentities($_POST['SO_subject']);
			$p_description=htmlentities($_POST['SO_description']);
			$p_amount =$_POST['SO_amount'];
			$date = new DateTime($_POST['SO_start']);
			$p_start_date=$date->format('Y-m-d');
			$date2 = new DateTime($_POST['SO_expired']);
			$p_expired_date=$date2->format('Y-m-d');
			$p_note=$_POST['SO_note'];
			SO_12_insert_recommendation($p_type,$p_subject,$p_description,$p_amount ,$p_start_date,$p_expired_date,$p_note);
			JO_location();
			
		}
		if($_POST["SO_query"]=="SaveTop"){
			$recommendation=$_POST['recommendation'];
			$start_date=$_POST['start'];
			$expired_date=$_POST['exp'];
			$mang=$_POST['key'];
			
			save_top($recommendation,$start_date,$expired_date,$mang);
			JO_location();
			
		}
		if($_POST["SO_query"]=="recommendation_updatedel"){
			if(isset($_POST['SO_checkdel']) && $_POST['SO_checkdel']!=""){
			$chude=$_POST['SO_checkdel'];
			foreach($chude as $gt){
			SO_12_updatedel_recommendation($gt);}
			}
			JO_location();
			
		}
		if($_POST["SO_query"]=="recommendation_update"){
			$p_type=$_POST['SO_type'];
			$p_subject=htmlentities($_POST['SO_subject']);
			$p_description=htmlentities($_POST['SO_description']);
			$p_amount =$_POST['SO_amount'];
			$date = new DateTime($_POST['SO_start']);
			$p_start_date=$date->format('Y-m-d');
			$date2 = new DateTime($_POST['SO_expired']);
			$p_expired_date=$date2->format('Y-m-d');
			$p_note=$_POST['SO_note'];
			$chude=$_POST['SO_chude'];
		
			SO_12_update_recommendation($p_type,$p_subject,$p_description,$p_amount ,$p_start_date,$p_expired_date,$p_note,$chude);
			JO_location();
			
		}
}
	
	

	/*
	 * ============================================== Get List of Topic ======================================
	 * Author			: Nguyem Hoang Quan
	 * Created Date		: 23/08/2011
	 * Modified Date	: 23/08/2011
	 */

	/*
	 * Get list of Recommendation with name of parent field
	 */
	 
	 
	 function SO_12_recommmendation_count(){
		$s_SQLCommand = "call SO_12_recommmendation_count();";
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	 function SO_12_get_date($key){
		$s_SQLCommand = "call SO_12_get_date($key);";
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	 function SO_12_recommmendation_pagelist($vt,$limit){
		$s_SQLCommand = "call SO_12_recommmendation_pagelist($vt,$limit);";
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	function SO_12_insert_recommendation($p_type,$p_subject,$p_description,$p_amount ,$p_start_date,$p_expired_date,$p_note){
		$s_SQLCommand = "call SO_12_insert_recommendation($p_type,'$p_subject','$p_description',$p_amount ,'$p_start_date','$p_expired_date','$p_note');";
		
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	function SO_12_update_recommendation($p_type,$p_subject,$p_description,$p_amount ,$p_start_date,$p_expired_date,$p_note,$chude){
		$s_SQLCommand = "call SO_12_update_recommendation($p_type,'$p_subject','$p_description',$p_amount ,'$p_start_date','$p_expired_date','$p_note',$chude);";
		
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	 function SO_12_get_type(){
		$s_SQLCommand = "call SO_12_get_type();";
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	 function SO_12_updatedel_recommendation($key){
		$s_SQLCommand = "call SO_12_updatedel_recommendation($key);";
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	function JO_012_gettype($key){
		$s_SQLCommand = "call JO_012_gettype($key);";
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	function JO_12_getlist_subject($type,$sea){
		$s_SQLCommand = "call JO_12_getlist_subject('$type','$sea');";
		
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	function JO_12_get_pagelist_subject($type,$vt,$limit,$sea){
		$s_SQLCommand = "call JO_12_get_pagelist_subject('$type',$vt,$limit,'$sea');";
		
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	function SO_12_recommended_list_getlist($key,$loai){
		$s_SQLCommand = "call SO_12_recommended_list_getlist($key,'$loai');";
		
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result; 
	}
	function SO_12_recommendation_getupdate($key){
		if(isset($key))
		{
		$s_SQLCommand = "call SO_12_recommendation_getupdate($key);";
		$rs_result = DataProvider::executeSQL($s_SQLCommand);
		return $rs_result;
		}
	}
	function save_top($recommendation,$start,$expired,$mang)
	{
		
		if($mang!="")
		{

			foreach($mang as $vt=>$gt)
			{
				$chuoi.=",".$gt;
			}
			$chuoi=substr($chuoi,1);//danh sach cac key co trong danh sach
				 $s_SQLCommand = "call SO_12_reset_recommended($recommendation);";

				 $s_SQLCommand = "call SO_12_reset_recommended($recommendation);";

				 $rs_result = DataProvider::executeSQL($s_SQLCommand);
				foreach($mang as $vt=>$gt)
						{
							 $vt=$vt+1;
							 $s_SQLCommand = "call JO_12_update_top($recommendation,'$start','$expired',$gt,$vt,'1');";
							 $rs_result = DataProvider::executeSQL($s_SQLCommand);
						 
						}
						
				
		}
		else
		{	
			$s_SQLCommand = "call SO_12_reset_recommended($recommendation);";
			$rs_result = DataProvider::executeSQL($s_SQLCommand);
		}
	}
	
?>